package com.lst.quartz.cluster.config;

import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @author shengtao
 * @Description:
 * @date 2018/12/17 12:56
 */
@Configuration
public class SysSchedulerFactoryBean {

    @Autowired
    private CustomJobFactory customJobFactory;

//    @Resource(name = "quartzDateSource")
    @Autowired
    private DataSource dataSource;

    @Bean
    public SchedulerFactoryBean schedulerFactoryBean(){
        SchedulerFactoryBean schedulerFactoryBean = new SchedulerFactoryBean();
        schedulerFactoryBean.setJobFactory(customJobFactory);
        schedulerFactoryBean.setDataSource(dataSource);
        schedulerFactoryBean.setConfigLocation(new PathMatchingResourcePatternResolver().getResource("classpath:quartz.properties"));
        return schedulerFactoryBean;
    }

//    @Bean
//    public Scheduler scheduler(){
//        Scheduler scheduler = schedulerFactoryBean().getScheduler();
//        return scheduler;
//    }

}
